# Maintainer: dorphell <dorphell@archlinux.org>
# Contributor: Jose Javier  <jojapa@terra.es>

pkgname=tftp-hpa
pkgver=5.2
pkgrel=6
pkgdesc="Official tftp server"
arch=('x86_64')
url="http://www.kernel.org/pub/software/network/tftp/tftp-hpa/"
license=('BSD')
backup=('etc/conf.d/tftpd')
install='tftpd.install'
depends=('readline>=6.0.00')
source=(http://www.kernel.org/pub/software/network/tftp/tftp-hpa/$pkgname-$pkgver.tar.gz 
       LICENSE
       tftpd.conf
       tftpd.service
       tftpd.socket
       tftp-hpa-0.49-fortify-strcpy-crash.patch)
md5sums=('3de3038e7c2bf6fc5d496825893ac8e7'
         '6ce21e27b6fdc1a1adf85c81e42aeecf'
         'b372088e550683df5ea8528ca6bbed1f'
         'ddd0028f77f131f3839bde92202305c4'
         'b04b9eb0bd049fa59dd518587a26d1c4'
         '22e8629ef19bc276a102c5d4d284c1bd')

prepare() {
  cd ${pkgname}-${pkgver}
  # fix #28103
  patch -Np1 -i ../tftp-hpa-0.49-fortify-strcpy-crash.patch
}

build() {
  cd ${pkgname}-${pkgver}
  ./configure --prefix=/usr --mandir=/usr/share/man --sbindir=/usr/bin --without-tcpwrappers 
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make INSTALLROOT="${pkgdir}" install
  install -D -m644 "${srcdir}/tftpd.conf" "$pkgdir/etc/conf.d/tftpd"
  install -d "${pkgdir}/srv/tftp"
  install -D -m644 "${srcdir}/tftpd.service" "${pkgdir}/usr/lib/systemd/system/tftpd.service"
  install -D -m644 "${srcdir}/tftpd.socket" "${pkgdir}/usr/lib/systemd/system/tftpd.socket"
  install -D -m644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  # Remove conflict with iputils
  rm "${pkgdir}/usr/share/man/man8/tftpd.8"  
}
